package com.umpay.junit.test.pos;

import static junit.framework.Assert.assertEquals;
import static org.springframework.test.util.AssertionErrors.fail;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.umfwechat.lightprogram.controller.pos.MerchantPosController;
import com.umfwechat.util.RedisUtil;

/*********************************************
 * JunitMerchantPosController.java
 * Author: Vermouth.yf
 * Created on: 2017-5-25
 *
 * Details:  com/umfwechat/lightprogram/controller/pos/MerchantPosController.java
 *           的 测试类
 *           
 ********************************************/

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:spring-context.xml"})

public class JunitMerchantPosController {
	
	@Resource
	MerchantPosController posController;
	
	private MockHttpServletRequest request;
    private MockHttpServletResponse response;
    
    private String pageNum;
    private String pageSize;
    private String loginAgentId;
    private String binbankname;
    
    
    private String storeId;
    
    //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓回调涉及的 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    private String merId;
    private String isRegect; //是否驳回
    
    
    
    
    static{
    	System.setProperty("resin.home", "E:\\developSoft\\resin\\resin-4.0.48");
//    	String url = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","junit.test.url", ""); 
//    	System.setProperty("resin.home", url);
    }
    
    @Before
    public void before()
    {
    	/**
    	 * 设置resin_home环境变量
    	 */
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        request.setCharacterEncoding("UTF-8");
        System.out.println("before run!");
    }
    
    @Test
    public void getBankNameList(){
           pageNum = "1";
           pageSize = "1000";   //试验模糊查询是否有效
           loginAgentId = "E379609107";  
           binbankname = "";
           
           
           RedisUtil.set("userid", 43200, "admin");  //设置3分钟
           RedisUtil.set("assistid", 43200, "a1");  //设置3分钟
           RedisUtil.set("password", 43200, "admin123");  //设置3分钟
           RedisUtil.set("dataSource", 43200, "SAAS");  //设置12小时
           
        try{
        	request.addParameter("pageNum", pageNum);
        	request.addParameter("pageSize", pageSize);
        	request.addParameter("binbankname", binbankname);
        	request.addParameter("loginAgentId", loginAgentId);
        	
            String resJson = posController.queryBankNameList(request,response);
            System.out.println("res="+resJson);
            String userid=RedisUtil.get("userid");
            System.out.println("缓存中取数值 userid:  \n"+userid);
//            String xxx = RedisUtil.get("xxx");
//            System.out.println("缓存中取莫须有的xxx: \n"+xxx);
        }catch (Exception e){
            e.printStackTrace();
            fail("test getBankNameList failed!");
        }
        
        assertEquals(response.getStatus(), 200);
    }
    
    @Test
    public void getStoreInf(){
           
        try{
        	storeId = "60000271";
        	request.addParameter("storeId", storeId);
        	
        	
            String resJson = posController.openPosSubmit(request,response);
            System.out.println("res="+resJson);
        }catch (Exception e){
            e.printStackTrace();
            fail("test getStoreInf failed!");
        }
        
        assertEquals(response.getStatus(), 200);
    }
    
    @Test
    public void posCallback(){
    	
    	try{
    		merId = "B2017060500000003";
    		isRegect = "0";
    		request.addParameter("merId", merId);
    		request.addParameter("isRegect", isRegect);
    		
//    		String getMerId = request.getParameter("merId");
//    		String getIsRegect = request.getParameter("isRegect");
//    		
//    		System.out.println("request  merId: "+getMerId + " isRegect: "+getIsRegect);
    		
    		String resJson = posController.posCallbackMethod(request,response);
    		System.out.println("res="+resJson);
    	}catch(Exception e){
    		e.printStackTrace();
            fail("test posCallback failed!");
    	}
    	
    	assertEquals(response.getStatus(), 200);
    }
     
}
